function [Poptim PCostO Woptim WCostO Coptim] = approach1(Y, X, MAXIT, alpha, lambda)
%Approach1 this model performs the optimization of a linear regression and
%after the optimization of P parameters of a feature program 
%input:
%X: data set
%Y: = Target variable

%return:
%Poptim: optimized parameters P (vector)
%PCostO: Cost of optimization processes of parameter P (vector)
%Woptim: Optimized parameters W (vector)
%WCostO: Cost of optimization processes of parameter P (vector)
%Coptim: optimum cost of the whole process (value)

%M examples in the training data set
M = size(X,1);

%N cities in the data set
N = size(X,2);

%limits of optimization
LB = [1, 7];
WB = [1, 7];

%optimum parameters and costs
Woptim = zeros(N+1,1);
Poptim = zeros(N,2);
WCostO = 0;
PCostO = 0;
Coptim = inf;

%dist = zeros(10 ,1);

%loop to try diferent initialization and finish with the best
for i=1:10
    
    %initialization with constraints
    P = featureParametersInitialization(M, N, WB, LB);
    
%     %DEBUG: Optimum P
%     Ps = [3 3;1 2;5 6;2 6;2 2];
%     P = Ps;
    
    %calculate features F from X using random parameters P
    [FY, F] = featureProgram(Y, X, P);
    
%     %DEBUG
%     Fo = csvread('Data\TestData\F.csv');
%     Fo = Fo(1:350-6,:);
%     sprintf ('dist %0.2f',sqrt(sum((Y(~isnan(Y),:) - FY) .^ 2)))
%     sprintf('dist %0.2f' ,sum(sqrt(sum(((Fo - F) .^ 2),2))) / size(F,1))

    %linear regression to find optimal prediction model parameters
    % arguments: (Features, Target,Iterations,Learning Rate, Regularization Factor)
    % Learning Rate ALFA
    %return [optimumParameters finalcost]
    
    [W, wCost] = linearRegressionModel(F, FY, MAXIT, alpha, lambda);

%     %try to optimum parameters for a feature program
%     [ P, pCost] = optimizeFeatureProgram(X, P, W, Y, MAXIT, 1, LB, WB);
    
    %second approach to find p*
    [ P, pCost] = fullSearch(  X, P, W, Y, 10, 10e-6,LB, WB );
    
%     
%     %DEBUG:
%     dist(i,1) = sqrt(sum((Ps(:) - P(:)).^ 2));

    %make predictions with the model and feature parameters optimized
    [H, cost] = modelPrediction(Y ,X, P, W);

    %store the best result in relation to the initialization
    if(cost < Coptim)
        Woptim = W;
        Poptim = P;
        Coptim = cost;
        WCostO = wCost;
        PCostO = pCost;
    end;
    
end;

%DEBUG:
% disp('end');
% mean(dist)
% std(dist)

end

